package com.junqson.je.common.util;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;

import java.util.Arrays;
import java.util.UUID;

/**
 * @Descriptions
 * @Company
 * @Author Junqson
 * @Date 2020/1/20 11:19
 * @Version 1.0
 */
public class AppUtil {
    public static void copyPropertiesIgnoreNull(Object src, Object target) {
        BeanUtil.copyProperties(src, target, true,
                CopyOptions.create().setIgnoreNullValue(true).setIgnoreError(true));
    }

    /**
     *
     * @param n  n<=32
     * @return
     */
    public static String genUUIDToken(int n) {
        return UUID.randomUUID().toString().replace("-", "").substring(0, n);

    }

    /**
     * 拼装redis key
     * @param preffix
     * @param suffix
     * @return
     */
    public static String getRedisKey(String preffix, String... suffix) {
        StringBuilder sb = new StringBuilder(preffix);
        Arrays.stream(suffix).forEach(sb::append);
        return sb.toString();
    }
}
